###########################################################################
# 车辆类
# 作者：张立业
# Copyright: 山东科技大学，交通学院。 All right reserved.
#
##########################################################################

import random
from skmath import rd
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

sim_t = 1000
class Car(QGraphicsRectItem):
    def __init__(self, i):
        ''' construction function of the class `Car`
        '''
        super().__init__()   #QGraphicsRectItem的构造函数
        self.id = i  # the id of the vehicle
        self.speed = 10  # the design speed of the vehicle
        self.pos = 0  # the initial position of the vehicle
        self.start_time = 0  # the time when the travel starts
        self.running = False

    def set_rand_color(self):
        '''
        设置车辆颜色为随机颜色
        '''
        r, g, b = random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)
        color = QColor(r, g, b)
        self.setBrush(QBrush(color))

    def set_size(self, x, y, w, h):
        '''
        设置车辆大小和初始位置

        x,y - 车的位置；
        w,h - 车的长度和宽度
        '''
        self.setRect( x, y, w, h)

    def run(self):
        ''' member function,
        '''
        print("car ", self.id, "running. Pos: ", self.pos)
        self.pos += rd.rand_speed(self.speed)  # call the function from package `skmath`